package com.jt.controller;

import com.jt.service.FileService;
import com.jt.vo.ImageVO;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController     //表示返回的数据是一个JSON
public class FileController {

    @Autowired
    private FileService fileService;


    @RequestMapping("/file")
    public String file(MultipartFile fileImage) throws IOException {
        String dir = "E:/TCGB_Three/TOOLS/images";
        File file1 = new File(dir);
        if (!file1.exists()){
            file1.mkdirs();     //不存在文件目录时,创建多级目录
        }
        String originalFilename = fileImage.getOriginalFilename();  //获取文件名
        File file = new File(dir + "/" + originalFilename);//定义文件的全路径
        fileImage.transferTo(file);     //根据全路径上传文件
        return "文件上传成功！！！";
    }

    /**
     * URL: http://localhost:8091/pic/upload?dir=image
     */

    @RequestMapping("/pic/upload")
    public ImageVO picUploadFile(MultipartFile uploadFile){

        return fileService.uploadFile(uploadFile);
//        String url="https://img.alicdn.com/imgextra/i3/1026559249/O1CN01I50ro62IC5kZkrurX_!!1026559249-0-beehive-scenes.jpg_250x250xz.jpg";
//        return ImageVO.success(url,800,800);
    }

}
















